<link rel="stylesheet" href="${basePath}/resources/common/libs/fileinput/css/fileinput.min.css">
<script src="${basePath}/resources/common/libs/fileinput/js/fileinput.js"></script>
<script src="${basePath}/resources/common/libs/fileinput/js/locales/zh.js"></script>
<script src="${basePath}/resources/common/js/base-file.js"></script>

<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
		<li class="fa fa-remove"></li>
	</button>
	<h4 class="modal-title">添加场景图</h4>
</div>

<div class="modal-body">
	<div class="form-group" id="file_container">
	    <input type="file" name="file" id="attachment">
	</div>
	
	<input type="hidden" id="id" name="id" value="${id}"/>
    <input type='hidden' value="${CSRFToken}" id='csrftoken'/>
    <input type="hidden" id="fileIds" name="fileIds"/>
    <div class="box-footer">
        <div class="pull-right">
            <button type="button" class="btn btn-default" data-btn-type="save_images">
            <i class="fa fa-pencil"></i> 下一步
            </button>
        </div>
   	</div>

</div>


<script>
    $(function (){
    	$("[data-btn-type='save_images']").click(function () {
    		saveImage();
        });
    });
    
    function saveImage(){
    	var id = $("#id").val();
    	var fileIds = $("#fileIds").val();
    	if(!fileIds){
    		modals.info('请先上传场景图再提交');
    		return;
    	}
    	ajaxPost(basePath + "/scene/saveImage/"+id+"/"+fileIds, null, function (result) {
            if (result.success) {
            	modals.closeWin("addImage");
            	modals.openWin({
					winId : 'showimg',
					title : '添加场景图',
					width : '1000px',
					url : basePath + "/scene/showImage/" + id
				});
            }
        });
    }
    
	$("#attachment").file({
	    fileinput: {
	        maxFileSize: 10240,
	        maxFileCount:1
	    },
	    fileIdContainer:"[name='fileIds']",
	    window:false
	});
</script>
